package com.clas.liu.myapplication.presenter.impl;

import android.os.Handler;
import android.os.Message;

import com.clas.liu.myapplication.model.event.SearchEvent;
import com.clas.liu.myapplication.model.impl.BaseModel;
import com.clas.liu.myapplication.model.impl.SearchModel;
import com.clas.liu.myapplication.presenter.i.ISearchPresenter;
import com.clas.liu.myapplication.view.activity.impl.BaseActivity;
import com.clas.liu.myapplication.view.activity.impl.SearchActivity;

/**
 * Created by liu on 2019/5/19.
 */

public class SearchPresenter extends BasePresenter<SearchActivity,SearchModel> implements ISearchPresenter {

    public SearchPresenter(SearchActivity view) {
        super(view);
    }

    @Override
    public void searchInfo(String s, int page_no, int page_size) {
        mModel.searchInfo(s,page_no,page_size);
    }

    @Override
    public void searchUser(String s, int page_no, int page_size) {
        mModel.searchUser(s,page_no,page_size);
    }

    @Override
    public void getHotKeys() {
        mModel.getHotKeys();
    }

    @Override
    protected SearchModel getModel(Handler handler) {
        return new SearchModel(handler);
    }

    @Override
    protected void eventReceive(Message msg) {
        SearchEvent searchEvent=((SearchEvent)msg.obj);
        switch (msg.what) {
            case SearchEvent.GET_HOT_KEYS_OK:

                mView.hotKeysReturn(searchEvent.getHotKeysRoot().getCode(),searchEvent.getHotKeysRoot().getHotKeys());
                break;
            case SearchEvent.GET_HOT_KEYS_FAIL:
                mView.failBecauseNetReturn(msg.what);
                break;
            case SearchEvent.SEARCH_INFO_OK:
                mView.InfoReturn(searchEvent.getInfoRoot().getCode(),searchEvent.getInfoRoot().getData());
                break;
            case SearchEvent.SEARCH_INFO_FAIL:
                mView.failBecauseNetReturn(msg.what);
                break;
            case SearchEvent.SEARCH_USER_OK:
                mView.UserReturn(searchEvent.getSearchUserRoot().getCode(),searchEvent.getSearchUserRoot().getData());
                break;
            case SearchEvent.SEARCH_USER_FAIL:
                mView.failBecauseNetReturn(msg.what);
                break;
        }
    }
}
